// 引用koa
const Koa = require('koa');
const Router = require('@koa/router')
const koaStatic = require('koa-static');
const path = require('path');
const cors = require('koa2-cors'); //跨域处理
const app = new Koa();
const router = new Router();
app.use(koaStatic(path.join(__dirname, '/public')));
//1路径 ，2异步回调函数
router.get('/',async (ctx,next)=>{
    ctx.body = '首页'
})

let url = 'http://172.25.38.252:3000'
// 首页商品
router.get('/goods',async (ctx,next)=>{
    let id = ctx.params.id
    ctx.body = [
        { title:'首页商品1', price:70, fm:`${url}/goods1.png`},
        { title:'YFyifu4', price:45, fm:`${url}/goods2.png`},
        { title:'YFyifu2', price:65, fm:`${url}/goods3.png`},
        { title:'YFyifu3', price:14, fm:`${url}/goods2.png`}
    ]
})

// 分类商品
router.get('/class',async (ctx,next)=>{
    let id = ctx.params.id
    ctx.body = [
        { title:'分类商品1', price:70, fm:`${url}/goods1.png`},
        { title:'YFyifu4', price:45, fm:`${url}/goods2.png`},
        { title:'YFyifu2', price:65, fm:`${url}/goods3.png`},
        { title:'YFyifu3', price:14, fm:`${url}/goods2.png`}
    ]
})

// 购物车商品
router.get('/cat',async (ctx,next)=>{
    ctx.body = await [
        { title:'购物车商品1', price:70,number:1, fm:`${url}/goods1.png`},
        { title:'YFyifu4', price:45,number:2, fm:`${url}/goods2.png`},
        { title:'YFyifu2', price:65,number:1, fm:`${url}/goods3.png`},
        { title:'YFyifu11', price:50,number:1, fm:`${url}/goods2.png`},
        { title:'YFyifu13', price:90,number:1, fm:`${url}/goods1.png`},
    ]
})


// 订单状态
router.get('/start',async (ctx,next)=>{
    let id = ctx.params.id
    ctx.body = [
        { title:'订单专状态1', price:70,start:1,  fm:`${url}/goods1.png`},
        { title:'YFyifu4', price:45,start:1,  fm:`${url}/goods2.png`},
        { title:'YFyifu2', price:65,start:1,  fm:`${url}/goods3.png`},
        { title:'YFyifu3', price:14,start:1, fm:`${url}/goods2.png`}
    ]
})



// 挂载路由
app.use(router.routes())
    .use(router.allowedMethods())
    .use(cors())

app.listen(3000,()=>{
    console.log('启动到3000端口')
});